package 剑指Offer._2130;

import general_class.TreeNode;

/**
 * @author yzh
 * @version 1.0
 * @date 2021/9/6 18:26
 * 对称的二叉树
 * 算法：树  深度优先搜索
 */
public class _28 {

    public boolean isSymmetric(TreeNode root) {
        if (root == null) return true;
        return dfs(root.left, root.right);
    }
    public boolean dfs(TreeNode r1, TreeNode r2) {
        if (r1 == null && r2 == null) return true;
        if (r1 == null || r2 == null || r1.val != r2.val) return false;
        return dfs(r1.left, r2.right) && dfs(r1.right, r2.left);
    }

}
